import Vue from 'vue';
import Router from 'vue-router';
import { Util, AuthGuard } from '@/utils';

Vue.use(Router);

const router = new Router({
    routes: [
                {
            path: '/bx_index/:bx_index?',
            name: 'bx_index',
            beforeEnter: (to: any, from: any, next: any) => {
                const routerParamsName = 'bx_index';
                const params: any = {};
                if (to.params && to.params[routerParamsName]) {
                    Object.assign(params, Util.formatMatrixParse(to.params[routerParamsName]));
                }
                const url: string = 'webapp/app/webapp/getappdata';
                const auth: Promise<any> = AuthGuard.getInstance().authGuard(url, params, router);
                auth.then(() => {
                    next();
                }).catch(() => {
                    next();
                });
            },
            meta: {  
                caption: '测试系统',
                viewType: 'APPINDEX',
                requireAuth: true,
            },
            component: () => import('@pages/bx/index/index'),
            children: [
                {
                    path: 'bx_worklisteditview/:bx_worklisteditview?',
                    name: 'bx_worklisteditview',
                    meta: {  
                        caption: 'worklist.views.editview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/bx/worklist-edit-view/worklist-edit-view'),
                },
                {
                    path: 'bx_worklistredirectview/:bx_worklistredirectview?',
                    name: 'bx_worklistredirectview',
                    meta: {  
                        caption: 'worklist.views.redirectview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/bx/worklist-redirect-view/worklist-redirect-view'),
                },
                {
                    path: 'bx_bxdeditview/:bx_bxdeditview?',
                    name: 'bx_bxdeditview',
                    meta: {  
                        caption: 'bxd.views.editview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/bx/bxdedit-view/bxdedit-view'),
                },
                {
                    path: 'template_bxdwfeditview3/:template_bxdwfeditview3?',
                    name: 'template_bxdwfeditview3',
                    meta: {  
                        caption: 'bxd.views.wfeditview3.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/template/bxdwfedit-view3/bxdwfedit-view3'),
                },
                {
                    path: 'template_bxdwfactionview/:template_bxdwfactionview?',
                    name: 'template_bxdwfactionview',
                    meta: {  
                        caption: 'bxd.views.wfactionview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/template/bxdwfaction-view/bxdwfaction-view'),
                },
                {
                    path: 'template_personeditview/:template_personeditview?',
                    name: 'template_personeditview',
                    meta: {  
                        caption: 'person.views.editview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/template/personedit-view/personedit-view'),
                },
                {
                    path: 'bx_bxdgridview/:bx_bxdgridview?',
                    name: 'bx_bxdgridview',
                    meta: {  
                        caption: 'bxd.views.gridview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/bx/bxdgrid-view/bxdgrid-view'),
                },
                {
                    path: 'template_persongridview/:template_persongridview?',
                    name: 'template_persongridview',
                    meta: {  
                        caption: 'person.views.gridview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/template/persongrid-view/persongrid-view'),
                },
                {
                    path: 'template_bxdwfstartview/:template_bxdwfstartview?',
                    name: 'template_bxdwfstartview',
                    meta: {  
                        caption: 'bxd.views.wfstartview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/template/bxdwfstart-view/bxdwfstart-view'),
                },
                {
                    path: 'bx_worklistgridview/:bx_worklistgridview?',
                    name: 'bx_worklistgridview',
                    meta: {  
                        caption: 'worklist.views.gridview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/bx/worklist-grid-view/worklist-grid-view'),
                },
                {
                    path: 'bx_bxdworkflowdesign/:bx_bxdworkflowdesign?',
                    name: 'bx_bxdworkflowdesign',
                    meta: {  
                        caption: 'bxd.views.workflowdesign.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/bx/bxdworkflow-design/bxdworkflow-design'),
                },
            ]
        },
        {
            path: '/login/:login?',
            name: 'login',
            meta: {  
                caption: '登录',
                viewType: 'login',
                requireAuth: false,
                ignoreAddPage: true,
            },
            beforeEnter: (to: any, from: any, next: any) => {
                router.app.$store.commit('resetRootStateData');
                next();
            },
            component: () => import('@components/login/login'),
        },
        {
            path: '/404',
            component: () => import('@components/404/404')
        },
        {
            path: '/500',
            component: () => import('@components/500/500')
        },
        {
            path: '*',
            redirect: 'bx_index'
        }
    ],
});

export default router;
